package com.yellowpage.bigdata.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.bigdata.data.WeekGonet;
import com.yellowpage.bigdata.dao.WeekGonetDao;

public class WeekGonetServiceImpl extends BaseServiceImpl implements WeekGonetService {
	  private WeekGonetDao weekGonetDao;
	
	  public void setWeekGonetDao(WeekGonetDao weekGonetDao) {
		  this.weekGonetDao = weekGonetDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public WeekGonet getWeekGonet(Long id){
	      return weekGonetDao.get(id);
	  }
	  
    public List<WeekGonet> getAllWeekGonet(){
        return weekGonetDao.getAll();
    }
    
    public List<Map> queryWeekGonetByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
"SELECT * FROM "+
"(SELECT  DAY_ID ,  SUM(CNTS) AS FOUR FROM TM_APPONOFF_ACTIVE_WEEK_GONET WHERE  `OFFSET` BETWEEN 2 AND 4 GROUP BY DAY_ID) c "+ 
"LEFT JOIN  (SELECT  DAY_ID AS DAY_IDL, SUM(CNTS) AS FIVE FROM TM_APPONOFF_ACTIVE_WEEK_GONET WHERE  `OFFSET` =5 GROUP BY DAY_ID) d"+ 
" ON c.DAY_ID=d.DAY_IDL WHERE 1=1 ").addCondition (" and DAY_ID >= :dayId ")
                                    .addCondition (" and DAY_ID <= :dayId_end "); 
   
				    			
					        	 	    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveWeekGonet(WeekGonet weekGonet){
        weekGonetDao.save(weekGonet);
    }
    
	  public void updateWeekGonet(WeekGonet weekGonet){
	      weekGonetDao.update(weekGonet);
	  }
	  
	  public void delete(List deleteList){
	      weekGonetDao.remove(deleteList);
	  }
	  
	  
	 
	
}	